package com.cskaoyan.controller;

import com.cskaoyan.bean.bo.AdminCategoryCreateBO;
import com.cskaoyan.bean.bo.AdminCategoryUpdateBO;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.bean.vo.admin_category.AdminCategoryCreateVO;
import com.cskaoyan.bean.vo.admin_category.AdminCategoryL1ListVO;
import com.cskaoyan.bean.vo.admin_category.AdminCategoryListVO;
import com.cskaoyan.service.AdminCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: Ryan
 * @CreateTime: 2022-09-07  19:28
 */
@RestController
@RequestMapping("/admin/category/*")
public class AdminCategoryController {
    @Autowired
    AdminCategoryService adminCategoryService;

    @RequestMapping("list")
    public BaseRespVo adminCategoryList() {
        BaseRespVo<Object> baseRespVo = new BaseRespVo<>();
        baseRespVo.setErrmsg("成功");
        baseRespVo.setErrno(0);
        CommonData<AdminCategoryListVO> CommonData = new CommonData<>();
        CommonData = adminCategoryService.selectAllAdminCategoryList();

        baseRespVo.setData(CommonData);
        return baseRespVo;
    }
    @RequestMapping("create")
    public BaseRespVo createAdminCategory(@RequestBody AdminCategoryCreateBO categoryCreateBO) {
        BaseRespVo<Object> baseRespVo = new BaseRespVo<>();
        baseRespVo.setErrmsg("成功");
        baseRespVo.setErrno(0);
        AdminCategoryCreateVO categoryCreateVO = adminCategoryService.createAdminCategory(categoryCreateBO);

        baseRespVo.setData(categoryCreateVO);
        return baseRespVo;
    }

    @RequestMapping("l1")
    public BaseRespVo l1AdminCategory() {
        BaseRespVo<Object> baseRespVo = new BaseRespVo<>();
        baseRespVo.setErrmsg("成功");
        baseRespVo.setErrno(0);
        CommonData<AdminCategoryL1ListVO> commonData = new CommonData<>();
        commonData = adminCategoryService.getL1AdminCategory();
        baseRespVo.setData(commonData);
        return baseRespVo;
    }

    @RequestMapping("update")
    public BaseRespVo updateAdminCategory(@RequestBody AdminCategoryUpdateBO categoryUpdateBO) {
        BaseRespVo<Object> baseRespVo = new BaseRespVo<>();
        baseRespVo.setErrmsg("成功");
        baseRespVo.setErrno(0);
        adminCategoryService.updateAdminCategory(categoryUpdateBO);
        return baseRespVo;
    }

    @RequestMapping("delete")
    public BaseRespVo deleteAdminCategory(@RequestBody AdminCategoryUpdateBO categoryUpdateBO) {
        BaseRespVo<Object> baseRespVo = new BaseRespVo<>();
        baseRespVo.setErrmsg("成功");
        baseRespVo.setErrno(0);
        adminCategoryService.deleteAdminCategory(categoryUpdateBO);
        return baseRespVo;
    }
}
